﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using DotConferenceCore.Logistique;

namespace WebInterface
{
    public partial class GestionSessions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var session2 = new Session(new DateTime(2009, 02, 11, 08, 00, 00),
                                           new DateTime(2009, 02, 11, 17, 00, 00));
                session2.Titre = "Game Design";

                var session3 = new Session(new DateTime(2009, 02, 12, 08, 00, 00),
                                           new DateTime(2009, 02, 12, 17, 00, 00));
                session3.Titre = "Programmation";

                var laConference = new Conference(new DateTime(2009, 02, 10, 08, 00, 00),
                                                  new DateTime(2009, 02, 15, 17, 00, 00));

                var sessionParallele = new SessionParallele(new DateTime(2009, 02, 10, 08, 0, 0),
                                                            new DateTime(2009, 02, 10, 13, 0, 0));

                var session4 = new Session(new DateTime(2009, 02, 10, 10, 0, 0), new DateTime(2009, 02, 10, 12, 0, 0))
                                   {
                                       Titre = "AI",
                                       Local = new Local()
                                   };

                var session5 = new Session(new DateTime(2009, 02, 10, 10, 0, 0), new DateTime(2009, 02, 10, 11, 30, 0))
                                   {
                                       Titre = "Langage de prog",
                                       Local = new Local()
                                   };

                var session6 = new Session(new DateTime(2009, 02, 10, 11, 00, 00),
                                           new DateTime(2009, 02, 10, 12, 00, 00))
                                   {
                                       Titre = "Game Design",
                                       Local = new Local()
                                   };

                sessionParallele.AjouterSession(session4);
                sessionParallele.AjouterSession(session5);
                sessionParallele.AjouterSession(session6);

                laConference.AjouterSession(session2);
                laConference.AjouterSession(session3);
                laConference.AjouterSession(sessionParallele);

                foreach (var session in laConference.Sessions)
                {
                    AddSession(session);
                }
            }
            else
            {
                Label1.Text = ListSessions.SelectedValue;
            }
        }

        private void AddSession(Session session)
        {
            ListSessions.Items.Add(String.Format("{0}:{1} - {2}", session.DateHeureDebut, session.DateHeureFin, GetSessionTitre(session)));
        }

        private static string GetSessionTitre(Session session)
        {
            if (session is SessionParallele)
            {
                var formatter = new StringBuilder();

                var sessionParallele = session as SessionParallele;

                foreach(var sousSession in sessionParallele.Sessions)
                {
                    formatter.Append(sousSession.Titre);
                    if (sousSession != sessionParallele.Sessions[sessionParallele.Sessions.Count - 1])
                    {
                        formatter.Append(" + ");
                    }
                }

                return formatter.ToString();
            }
            else
            {
                return session.Titre;
            }
        }
    }
}
